# -*- coding: utf-8 -*-
from datetime import timedelta
from jms_hi.dwd.tms.dwd_tmsnew_shipment_stop_union_base_hi import jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_union_base_hi import jms_dwd__dwd_tmsnew_shipment_union_base_hi
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dim__dim_dependent = SparkSqlOperator(
    task_id='jms_dim__dim_dependent',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    task_concurrency=1,
    pool_slots=1,
    master='yarn',
    name='jms_dim__dim_dependent_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms_hi/dim/dim_dependent/execute.sql',
    driver_cores=1 , 
    driver_memory='1g' , 
    executor_cores=1 , 
    executor_memory='1G' , 
    depends_on_past=True,
    num_executors=1 , 
    conf={'spark.dynamicAllocation.enabled'                  : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                    : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 1 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '1G' , 
          'spark.sql.shuffle.partitions'                     : 1,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 1000,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 1000,  # 每天生成 20 个分区
              'hive.optimize.bucketmapjoin': 'true',
              'hive.optimize.bucketmapjoin.sortedmerge': 'true',
              'hive.input.format': 'org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat',
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=50),
)

jms_dim__dim_dependent << [jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi,jms_dwd__dwd_tmsnew_shipment_union_base_hi]
